package com.oa.cc.action;

import java.util.ArrayList;
import java.util.List;

import org.apache.struts2.ServletActionContext;

import com.oa.cc.service.AskAuditService;
import com.oa.cc.service.WorkStreamService;
import com.oa.domain.Ask;
import com.oa.domain.AskAudit;
import com.oa.domain.Emp;
import com.oa.domain.Workstream;
import com.opensymphony.xwork2.ActionSupport;

public class WorkStreamAction extends ActionSupport{
	private static final long serialVersionUID = 1L;
	
	private Workstream workstream;
	private WorkStreamService workStreamService;
	private List<Workstream> listWork;
	private AskAuditService askAuditService;
	private List<Ask> listAsk;

	public void setListAsk(List<Ask> listAsk) {
		this.listAsk = listAsk;
	}
	public List<Ask> getListAsk() {
		return listAsk;
	}
	public void setAskAuditService(AskAuditService askAuditService) {
		this.askAuditService = askAuditService;
	}
	public AskAuditService getAskAuditService() {
		return askAuditService;
	}
	public List<Workstream> getListWork() {
		return listWork;
	}
	public void setListWork(List<Workstream> listWork) {
		this.listWork = listWork;
	}
	
	public void setWorkStreamService(WorkStreamService workStreamService) {
		this.workStreamService = workStreamService;
	}
	
	public void setWorkstream(Workstream workstream) {
		this.workstream = workstream;
	}
	public Workstream getWorkstream() {
		return workstream;
	}
	
	//LEFT流程管理
	public String execute() throws Exception {
		listWork = workStreamService.getWordsByExample(new Workstream());
		System.out.println("工作流程长度："+listWork.size());
		return SUCCESS;
	}
	
	//LEFT我要发文
	public String goWork() throws Exception {
		listWork = workStreamService.getWordsByExample(new Workstream());
		System.out.println(""+listWork.size());
		return "goWork";
	}
	
	//working界面left发文按钮点击界面具体操作
	public String working() throws Exception {
		String wsid = ServletActionContext.getRequest().getParameter("wsid");
		System.out.println("wsid:"+wsid);
		workstream = workStreamService.getWordStreamById(Long.parseLong(wsid));
		/*System.out.println(w.getWsname());
		Set<WorkstreamStep> s = w.getWorkstreamSteps();
		for(WorkstreamStep works:s){
			System.out.println(works.getStep().getStepname());
		}*/
		System.out.println("名称："+workstream.getWsname());
		return "working";
	}
	
	public String acceptWork() throws Exception {
		Emp emp = (Emp) ServletActionContext.getRequest().getSession().getAttribute("emp");
		List<AskAudit> list = askAuditService.getAskAuditByEmpno(emp.getEmpno());
		if(list.size()>0){
			listAsk = new ArrayList<Ask>();
			for(AskAudit a:list){
				//System.out.println("请求名:"+a.getAsk().getTitle());
				listAsk.add(a.getAsk());
			}
		}
		return "acceptWork";
	}
	
}
